﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace Nojin.Deployment
{
    public partial class NewVersionMessageForm : Form
    {
        public NewVersionMessageForm()
        {
            InitializeComponent();            
        }

        public NewVersionMessageForm(UpdateInfo updateInfo) : this()
        {
            this.NewVersionInfo = updateInfo;
        }

        private UpdateInfo newVersionInfo;
        public UpdateInfo NewVersionInfo
        {
            get { return newVersionInfo; }
            set
            {
                newVersionInfo = value;
                labelName.Text = value.Name;
                labelVersion.Text = value.Version.ToString();
                labelReleaseDate.Text = Texts.GetShortDateText(value.ReleaseDate);
                labelPackageSize.Text = string.Format(Texts.FileSizePattern,value.PackageSize);
                labelUpdateIsNotArbitary.Visible = !value.Arbitary;
                linkLabelShowChangeLog.Visible = !string.IsNullOrEmpty(value.ChangeLogFilePath);                
            }
        }
        
        private void linkLabelShowChangeLog_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(newVersionInfo.ChangeLogFilePath);
            //ChangeLogViewForm changeLogViewForm = new ChangeLogViewForm(newVersionInfo.ChangeLogFilePath);
            //changeLogViewForm.Show();
        }

        private void buttonDownload_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void NewVersionMessageForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            if (e.KeyCode == Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }
    }
}